﻿using System;
using System.Collections.Generic;

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CFM.Common;
using CFM.DTO;
namespace CFM
{
    public partial class frmManager : Form
    {
        private frmMain _frmMain = null;
        public frmManager()
        {
            InitializeComponent();
        }

        private void mn_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menu = sender as ToolStripMenuItem;
            switch (menu.Name)
            { 
                case "mnInput":
                    ShowFrom(new frmInput());
                    break;
                case "mnViewBill":
                    ShowFrom(new frmViewBill());
                    break;
                case "mnInventorySatistic":
                    ShowFrom(new frmInventorySatistic());
                    break;                
                case "mnProduct":
                    ShowFrom(new frmProduct());
                    break;
                case "mnProductGroup":
                    ShowFrom(new frmCategory());
                    break;
                case "mnProvider":
                    ShowFrom(new frmProvider());
                    break;
                case "mnSalesSatistic":
                    ShowFrom(new frmSalesSatistic());
                    break;
                case "mnTable":
                    ShowFrom(new frmTable ());                   
                    break;
                case "mnTableGroup":
                    ShowFrom(new frmTableGroup());                  
                    break;
                case "mnUnit":
                    ShowFrom(new frmUnit());
                    break;
                case "mnUser":
                    ShowFrom(new frmUser());
                    break;
                case "mnConfig":
                    ShowFrom(new frmConfig());
                    break;
                case "mnChangePassword":
                    ShowFrom(new frmChangePassword());
                    break;
                case "mnExit":
                    this.Close();
                    break;
                case "mnMain":                                   
                    if (_frmMain == null || _frmMain.IsDisposed)                    
                        _frmMain = new frmMain();                    
                    _frmMain.StartPosition = FormStartPosition.CenterParent;
                    _frmMain.Show();                    
                    break; 
                case "mnReLogin":
                    Const.CurrentUser = new User();
                    lblUserName.Text = string.Empty;
                    ShowFrom(new frmLogin());
                    if (!string.IsNullOrEmpty(Const.CurrentUser.UserId))
                    {
                        CheckPermession();
                        lblUserName.Text = "Xin chào " + Const.CurrentUser.FullName;
                    }
                    break;
            }
        }

        private void ShowFrom(Form frm)
        {
            frm.StartPosition = FormStartPosition.CenterParent;            
            frm.ShowDialog();
        }

        private void frmManager_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Const.CurrentUser.UserId))
            {
                frmLogin frm = new frmLogin();
                frm.ShowDialog();                 
            }
            if (!string.IsNullOrEmpty(Const.CurrentUser.UserId))
            {
                CheckPermession();
                lblUserName.Text = "Xin chào " + Const.CurrentUser.FullName;
            }
            
        }

        private void CheckPermession()
        {
            if (Const.CurrentUser.RoleId == eRole.ThuNgan.GetHashCode().ToString())
            {
                mnInput.Enabled = false;
                mnConfig.Enabled = false;
                mnUser.Enabled = false;
                mnList.Enabled = false;
                mnSatistic.Enabled = false;
            }
            else
            {
                mnInput.Enabled = true;
                mnConfig.Enabled = true;
                mnUser.Enabled = true;
                mnList.Enabled = true;
                mnSatistic.Enabled = true;   
            }

        }

        
    }
}
 